﻿using System;
using System.Collections.Generic;

namespace gt.framework.Log
{
    public sealed class LogManager
    {
        private static Dictionary<string, ILogWrapper> m_logContainer = new Dictionary<string, ILogWrapper>();
        private const string DefaultLogName = "DefaultLog";

        static LogManager()
        {
            ILogWrapper log = new FileLogWrapper();
            m_logContainer.Add(DefaultLogName, new FileLogWrapper());
        }
        public static ILogWrapper DefaultLog
        {
            get { return GetLog(DefaultLogName); }
        }

        public static void AddLogger(ILogWrapper logger)
        {
            if (logger == null) throw new ArgumentNullException("log");
            if (m_logContainer.ContainsKey(logger.Name))
                throw new InvalidOperationException(string.Format("name={0} log has exist!", logger.Name));
            m_logContainer.Add(logger.Name, logger);
        }
        public static void AddLogger(List<ILogWrapper> loggers)
        {
            foreach (var log in loggers)
            {
                AddLogger(log);
            }
        }

        public static ILogWrapper GetLog(string name)
        {
            ILogWrapper log = null;
            m_logContainer.TryGetValue(name, out log);
            return log;
        }
    }
}
